import java.util.Scanner;

/**
 * @author vivi
 * @description
 * @date 2024/5/18
 */
public class demo3 {
    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
        int m = scanner.nextInt(), n = scanner.nextInt();
        char[] arr1 = scanner.next().toCharArray();
        char[] arr2 = scanner.next().toCharArray();
        int[][] dp = new int[m+1][n+1];

        for (int i = 1; i < m+1; i++) {
            for (int j = 1; j < n+1; j++) {
                if (arr1[i-1] == arr2[j-1]) {
                    dp[i][j] = arr1[i-1] + arr2[j-1] + 1;
                }else {
                    dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
                }
            }
        }
        System.out.println(dp[m][n]);
    }
}
